package com.dbsop.domain.rest.query;

import com.dbsop.common.enums.FlagConnect;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

/**
 * 等于搜索
 */
public class RestEqQuery extends RestConditionQuery {

    private Object value;

    public RestEqQuery(String columnName, Object value) {
        super(columnName);
        this.value = value;
    }

    public RestEqQuery(String columnName, FlagConnect flagConnect, Object value) {
        super(columnName, flagConnect);
        this.value = value;
    }


    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }



    @Override
    public QueryBuilder extractBoolQuery() {
        if (value == null){
            return QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(getColumnName()));
        }else {
            return QueryBuilders.termQuery(getColumnName(), value);
        }
    }
}
